package com.nmes.naljava.server;

import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.nmes.naljava.PMF;
import com.nmes.naljava.entity.Account;

@SuppressWarnings("serial")
public class ImageSource extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse resp) throws IOException {
        resp.setContentType("image/jpeg");
        PersistenceManager pm = PMF.get().getPersistenceManager();
        Key k = KeyFactory.createKey( Account.class.getSimpleName(), new Integer(request.getParameter("id")	).intValue());
        Account a = pm.getObjectById(Account.class,k);
        if( a.getImageObject().getBytes().length > 0 )
        {
            //resp.getOutputStream().write(pm.getObjectById(Account.class, Long.valueOf(req.getParameter("id").toString())).getImage().getBytes());
        	resp.getOutputStream().write( a.getImageObject().getBytes());
        	resp.getOutputStream().flush();
            resp.getOutputStream().close();
        }

        
    }
};